<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>次品列表</title>

<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script> 
<style type="text/css">
#searchbar{
   margin-bottom: 10px;
   margin-left:15px;
  }
  .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search {
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>

<body style="padding:6px; overflow:hidden;">
<div class="navbar">
		<span>您当前的位置：</span>
		商品管理 &gt; 次品列表
</div>

<%--<form action="	" method="post" >
 <div id="searchbar"><br>

商品编号：<input type="text" id="productId" name="productId" value="${defective.productId}">&nbsp;&nbsp;
商品名称：<input type="text" id="productName" name="productName" value="${defective.productName}" />&nbsp;&nbsp;
审核状态：<select id="checkState" name="checkState">
         		<option value="-1">请选择</option>
         		<option value="0" ${commodity.checkState == 0 ? "selected='selected'" : ""}>未审核</option>
         		<option value="1" ${commodity.checkState == 1 ? "selected='selected'" : ""}>已审核</option>
         		<option value="2" ${commodity.checkState == 2 ? "selected='selected'" : ""}>已拒绝</option>
         	</select><br><br>
货品编号：<input type="text" id="prodNo" name="prodNo" value="${commodity.prodNo}">&nbsp;&nbsp;
创建时间：<input type="text" id="createStartDate" name="createStartDate" value="${commodity.createStartDate}" class="Wdate" value="" size="21" readonly="readonly"
			onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,maxDate:'#F{$dp.$D(\'createEndDate\')||\'2020-10-01\'}'})"> - 
		 <input type="text" id="createEndDate" name="createEndDate" value="${commodity.createEndDate}" class="Wdate" value="" size="21" readonly="readonly"
			onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true,autoPickDate:true,minDate:'#F{$dp.$D(\'createStartDate\')||\'2013-01-01\'}'})" >

         <input type="submit" id="btnSearch" value="查询" class="l-button-search" />
           <input type="button" id="btnReset" value="重置" class="l-button-search" />
</div> --%>
<br />
<form action="#" name="queryForm" id="queryForm" method="POST" >
<div id="searchbar"><br>
次品编号：<input type="text" id="id" name="id" value="${defective.id}" />&nbsp;&nbsp;
商品名称：<input type="text" id="commoName" name="commoName" value="${defective.commoName}" />&nbsp;&nbsp;
仓库名称：<input type="text" id="whName" name="whName" value="${defective.whName}" />&nbsp;&nbsp;
处理方式： <select id="dealWith" name="dealWith">
         		<option value="-1">请选择</option>
         		<option value="1" ${defective.dealWith == 1 ? "selected='selected'" : ""}>退货</option>
<%--          		<option value="2" ${defective.dealWith == 2 ? "selected='selected'" : ""}>换货</option>
 --%>         		<option value="3" ${defective.dealWith == 3 ? "selected='selected'" : ""}>其他</option>
         		<option value="4" ${defective.dealWith == 4 ? "selected='selected'" : ""}>无法修复</option>
         </select> &nbsp;&nbsp;
处理状态： <select id="storageState" name="storageState">
         		<option value="-1">请选择</option>
         		<option value="0" ${defective.storageState == 0 ? "selected='selected'" : ""}>未审核</option>
         		<option value="1" ${defective.storageState == 1 ? "selected='selected'" : ""}>已审核</option>
         		<option value="2" ${defective.storageState == 2 ? "selected='selected'" : ""}>已完成</option>
         </select> &nbsp;&nbsp;
         <input type="submit" id="btnSearch" value="查询" class="l-button-search" />
         <input type="button" id="btnReset" value="重置" class="l-button-search" />
</div>
</form>
<br />
<div id="maingrid" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- 展示列表数据  -->
</div>

	<script>
    var basePath='${BasePath}';
    var grid = null;
	
    $(function () {
    	 // 重置
        $("#btnReset").click(function(){
    		$('#searchbar :input').not(':submit, :button, :reset').val('').removeAttr('checked').removeAttr('selected');
    	});
    	
       /*  $("#id").show()表示display:block, 
        $("#id").hide()表示display:none;  */
        grid = $("#maingrid").ligerGrid({
            columns: [
            { display: '次品编号', name: 'id'},
            { display: '货品编号', name: 'prodNo'},
            { display: '商品编号', name: 'commoNo'},
            { display: '商品名称', name: 'commoName'},
            { display: '规格', name: 'specName'},
            { display: '采购单号', name: 'poNo'},
            { display: '次品数量', name: 'defectiveNumber'},
            { display: '次品原因', name: 'defectiveReason'},
           /*  { display: '处理方式', name: 'dealWith' ,render:function(rowdata,rowindex,value){
	            var text = null;
	            switch(value){
		            case 1: text="退货"; break;
		            case 2: text="换货"; break;  
		            case 3: text="其他"; break;
		            case 4: text="无法修复"; break; 
	            default : break; 
            } 
            return text;
       	 	}},*/
            { display: '仓库名称', name: 'whName'},
            { display: '入库方式', name: 'storageMethods',render:function(rowdata,rowindex,value){
	            var text = null;
	            switch(value){
		            case 1: text="采购入库"; break;
		            case 2: text="销售退货入库"; break;
		            case 3: text="其他入库"; break;  
		            default : break; 
            	}
            return text;
       	 	}},
           /*  { display: '所属采购单', name: 'poNo'}, */
           /*  { display: '供应商编号', name: 'supCode'}, */
            { display: '供应商名称', name: 'supName'},
            { display: '录入时间', name: 'createTime'},
            { display: '入库人员', name: 'storageMan'},
            { display: '处理状态 ', name: 'storageState',render:function(rowdata,rowindex,value){
	            var text = null;
	            switch(value){
		            case 0: text="未审核"; break;
		            case 1: text="已审核"; break;  
		            case 2: text="已生成退货单"; break;
		            default : break; 
            	}
            return text;
       	 	}},
            { display: '处理时间', name: 'dealwithTime'},
            { display: '处理人员', name: 'dealwithMan'},
           
            { display: '操作', isSort: false, render: function (rowdata, rowindex, value){
            	var  h = "";
            	if(rowdata.storageState == 0){
                   	h += "<a href='javascript:approveDefective(" + rowindex + ")'>审核</a> ";
            		h +=  "<a href='javascript:updateDefective(" + rowindex + ")'>修改</a> ";
               		h += "<a href='javascript:deleteDefective(" + rowindex + ")'>删除</a> ";
             	}
                 h += "<a href='javascript:showPoDetail(" + rowindex + ")'>详情</a> "; 
               /*  h += "<a href='javascript:showPoDetail(\"" + rowdata.id + "\", 2)'>详情</a>&nbsp;"; */
                return h;
            }}
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
					{name: "id", value:$("#id").val()},
					{name: "commoName", value:$("#commoName").val()},
					{name: "whName", value:$("#whName").val()},
					{name: "dealWith", value:$("#dealWith").val()},
					{name: "storageState", value:$("#storageState").val()}
                    ],
			url: basePath+'/product/defectivemgt/list_defective.do',
			toolbar: toolbar
        });
    });
    var toolbar = '';
    toolbar = {
    	items: [
    			{ text: "新增次品", click: addDefective, icon: "add" }
        		]
       		 };
    
    /**
     * 新增品牌信息
     */
    function addDefective(){
    		var url=basePath+'/product/defectivemgt/to_add_defective.do';
        	url+="?pTabid="+WIN_TAB.getSelectedTabItemID();
        	window.parent.f_addTab('新增次品','新增次品',url);
    }
    
    /**
     * 采购单详情
     * @param poNo
     */
    function showPoDetail(rowindex) {
    	var id = grid.getData()[rowindex].id;
        var url = basePath+'/product/defectivemgt/showPoDetail.do?id=' + id;
        url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
   	    window.parent.f_addTab('次品详情','次品详情',url);
    }
     
    /**
     * 修改次品信息
     */
    function updateDefective(rowindex){
    	 var defectiveId = grid.getData()[rowindex].id;
         var url = basePath+'/product/defectivemgt/to_update_defective.do?defectiveId='+defectiveId;
         url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
    	 window.parent.f_addTab('修改品牌','修改品牌',url);
    }
    
    /**
     * 删除次品信息
     */
    function deleteDefective(rowindex) {
    	var id=grid.getData()[rowindex].id;
    	$.ligerDialog.confirm('确定删除',
    		function(yes) {if (yes) {
    			$.post(
    					basePath+ '/product/defectivemgt/deleteDefective.do',
    					{id : id},
    					function(data) {
    						if (data == 'success') {
    							window.parent.f_tip('删除成功');
    							window.location.reload();
    						} else if (data == 'fail') {
    							window.parent.f_tip('删除失败');
    						}else{
    							window.parent.f_tip(data);
    						};
    					}
    			);
    		};
    	});
    }
    
    
    var toolbar;
    var roles = new Array();
    '<c:forEach items="${roleVos}" var="item">';
    roles.push('${item.roleCode}');
    '</c:forEach>';
    
    var rpm = 0;
	if (roles.length > 0) {
		var ex = [];
		var add = [];
		var items = [];
		for(var i=0; i<roles.length; i++) {
			//商品主管,管理员
    		if (roles[i] == 'GOOD_PERSON' || roles[i] == 'GOODS_SUPERVISOR' || roles[i] == 'SYSTEM_ADMIN') {
    			add = [{ text: "新增次品",id:"add", click: addCommodity, icon: "add"},{ line: true }];
    		}
    		if (roles[i] == 'GOODS_SUPERVISOR' || roles[i] == 'FINANCIAL_PRINCIPAL' || roles[i] == 'SYSTEM_ADMIN') {
    			ex = [{text: '导出EXCEL', click: doExportExcel, icon: "print"},{ line: true }];
    		}
    	}
		items = items.concat(ex);
		items = items.concat(add);
		toolbar = {items : items};
	}
	
	
	
	function approveDefective(rowindex){
		var id = grid.getData()[rowindex].id;
    	$.ligerDialog.confirm('确定通过审核',
    		function(yes) {if (yes) {
			$.ajax({
			       async: false,
			       type: 'post',
			       dataType: 'text',
			       data: {
			    	   defectiveId:id
			       },
			       url: basePath + "/product/defectivemgt/defectiveAduit.do",
			       success: function (data) {
			     	  if(data == 'fail'){
			     		  	window.parent.f_tip('审核失败');
			     	  }else{
							window.parent.f_tip('审核成功');
							var tabId = window.top.tab.getSelectedTabItemID();
							window.top.tab.reload(tabId);
			     	  }
			       }
			   }); 
		  }/* else{
			  window.parent.f_tip('数据错误');
		  }  */
    	});
	 }
    //导出商品信息
    /* function doExportExcel() {
    	var commoNo=$("#commoNo").val();
    	var commoName=$("#commoName").val();
    	var checkState=$("#checkState").val();
    	var prodNo=$("#prodNo").val();
    	var createStartDate=$("#createStartDate").val();
    	var createEndDate=$("#createEndDate").val();
    	
    	var params = '?commoNo='+commoNo+'&commoName='+commoName+'&checkState='+checkState
    			+'&prodNo='+prodNo+'&createStartDate='+createStartDate+'&createEndDate='+createEndDate;
    	if(commoNo == "" && commoName == "" && prodNo == "" && createStartDate == "" && createEndDate == ""){
    		$.ligerDialog.warn("导出商品，查询条件不能为空");
    	}else{
    		var url = basePath+'/product/commoditymgt/doExportExcel.do'+encodeURI(encodeURI(params));
			window.location.href = url;
    	}
	} */
    
   
    </script>
	
</body>
</html>